﻿package mortal.game.view.FirstRechargeDay500.rechargeDaily
{
    import Message.Public.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.rebate.item.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class RechargeDailyTotalModule extends BaseWindow
    {
        protected var _mbg:GImageBitmap;
        protected var _list:CellsGridSprite;
        protected var _rechargeNum:BitmapNumberText;
        protected var _getBtn:GLoadingButton;
        protected var _togoBtn:GLoadingButton;
        protected var _hasReNum:GTextFiled;
        private var _info:Object;
        private static var _instance:RechargeDailyTotalModule;

        public function RechargeDailyTotalModule(param1:ILayer = null)
        {
            super(param1);
            setSize(625, 560);
            title = "" + Language.getString(71059);
            return;
        }// end function

        override protected function configParams() : void
        {
            _titleSpriteHight = 120;
            super.configParams();
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._mbg = UIFactory.gImageBitmap(ImagesConst.rechargeActTotalBg, 7, 36, this);
            this._list = UIFactory.getUICompoment(CellsGridSprite);
            this._list.colNum = 3;
            this._list.vCellWid = 80;
            this._list.hCellWid = 80;
            this._list.genCellFun = this.genItem;
            this._list.genCells(6);
            this._list.x = 197;
            this._list.y = 234;
            this.addChild(this._list);
            this._rechargeNum = UIFactory.bitmapNumberText(380, 61, "rechargeActTotalNum.png", 26, 35, -2, this, 9, 1);
            this._rechargeNum.text = "3888";
            this._getBtn = UIFactory.gLoadingButton(ImagesConst.DailyRewardBtn_upSkin, 264, 418, 103, 40, this);
            this._getBtn.label = "";
            this._togoBtn = UIFactory.gLoadingButton(ImagesConst.FirstRechargeBtn_upSkin, 223, 474, 188, 50, this);
            this._togoBtn.label = "";
            this._hasReNum = UIFactory.gTextField("", 485, 132, 100, 20, this, GlobalStyle.textFormatLv.setBold(true));
            this.addEvs(true);
            this.setBtn(this._getBtn, false);
            this.onFlashRW(null);
            this._togoBtn.configEventListener(MouseEvent.CLICK, this.gotoRc);
            this._getBtn.configEventListener(MouseEvent.CLICK, this.onCk);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this.addEvs(false);
            this.setBtn(this._getBtn, false);
            this._mbg = null;
            this._list = null;
            this._rechargeNum = null;
            this._getBtn = null;
            this._togoBtn = null;
            this._hasReNum = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function addEvs(param1:Boolean) : void
        {
            EventUtil.addSelfEvent(EventName.RechargeDailyGetRwBack, this.onGetRwBack, param1);
            EventUtil.addNetEvent(ServerCommand.RechargeDailyGetFlag, this.onFlashRW, param1);
            return;
        }// end function

        private function onGetRwBack(event:DataEvent) : void
        {
            var _loc_3:RebateItem = null;
            MsgManager.showRollTipsMsg("" + Language.getString(71060));
            if (this._list == null)
            {
                return;
            }
            var _loc_2:int = 0;
            while (_loc_2 < this._list.cellArr.length)
            {
                
                _loc_3 = this._list.cellArr[_loc_2];
                _loc_3.flyIcon();
                _loc_2++;
            }
            return;
        }// end function

        public function onFlashRW(param1:Object) : void
        {
            this.updateRw();
            this.updateBtn();
            return;
        }// end function

        private function genItem() : RebateItem
        {
            var _loc_1:* = UIFactory.getUICompoment(RebateItem);
            return _loc_1;
        }// end function

        private function updateRw() : void
        {
            var _loc_3:SPlayerItem = null;
            var _loc_4:RebateItem = null;
            if (isDisposed)
            {
                return;
            }
            var _loc_1:* = RechargeDailyUtil.getShowRwData();
            if (_loc_1 == null || _loc_1.length == 0)
            {
                return;
            }
            this._list.genCells(_loc_1.length);
            var _loc_2:int = 0;
            while (_loc_2 < _loc_1.length)
            {
                
                _loc_3 = _loc_1[_loc_2];
                _loc_4 = this._list.cellArr[_loc_2];
                _loc_2++;
            }
            this._rechargeNum.text = "" + RechargeDailyUtil.getRechargeGoldNum();
            this._hasReNum.text = Language.getString(71061) + Cache.instance.rebate.rechargeSum;
            return;
        }// end function

        public function updateBtn() : void
        {
            if (this._getBtn == null)
            {
                return;
            }
            var _loc_1:* = RechargeDailyUtil.getBtnState();
            switch(_loc_1)
            {
                case 0:
                {
                    this.hide();
                    break;
                }
                case 1:
                {
                    this.setBtn(this._getBtn, true);
                    break;
                }
                case 2:
                {
                    this.setBtn(this._getBtn, false);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private function setBtn(param1:GLoadingButton, param2:Boolean) : void
        {
            if (param2)
            {
                param1.enabled = true;
                param1.filters = null;
                EffectManager.glowFilterReg(param1);
            }
            else
            {
                EffectManager.glowFilterUnReg(param1);
                param1.enabled = false;
                param1.filters = [FilterConst.colorFilter2];
            }
            return;
        }// end function

        private function onCk(event:MouseEvent) : void
        {
            var _loc_2:int = 0;
            if (RechargeDailyUtil.hasRw())
            {
                _loc_2 = RechargeDailyUtil.hasGetIndex + 1;
                Dispatcher.dispatchEvent(new DataEvent(EventName.RechargeDailyGetRw, _loc_2));
            }
            return;
        }// end function

        private function gotoRc(event:MouseEvent) : void
        {
            GameUtil.gotoRecharge(ModuleTypeConst.FirstRecharge500);
            return;
        }// end function

        public static function get hasInstance() : Boolean
        {
            return _instance != null;
        }// end function

        public static function get instance() : RechargeDailyTotalModule
        {
            if (!_instance)
            {
                _instance = new RechargeDailyTotalModule;
            }
            return _instance;
        }// end function

    }
}
